import * as THREE from 'three';
import PCDLoader from "@/loader/PCDLoader.ts"

function createGeometry(data) {
  let geometry = new THREE.BufferGeometry();

  let positionAttr = new THREE.Float32BufferAttribute(data.position || [], 3);
  // positionAttr.usage = THREE.DynamicDrawUsage;

  let intensityAttr = new THREE.Float32BufferAttribute(data.intensity || [], 1);
  // intensityAttr.usage = THREE.DynamicDrawUsage;

  let colorAttr = new THREE.Uint8BufferAttribute(data.color || [], 3);
  // colorAttr.usage = THREE.DynamicDrawUsage;

  geometry.setAttribute('position', positionAttr);
  geometry.setAttribute('intensity', intensityAttr);
  geometry.setAttribute('color', colorAttr);
  return geometry;
}
export default class Points extends THREE.Points {
  completed = false;
  loading = false;
  timeStamp = 0;
  loader = new PCDLoader();
  constructor(material) {
    let geometry = createGeometry();
    super(geometry, material);
  }

  updateData(data) {
    let geometry = this.geometry
    geometry.dispose();
    this.geometry = createGeometry(data);
    this.geometry.computeBoundingSphere();
    // this.dispatchEvent({ type: Event.POINTS_CHANGE });
  }
}